package com.itheima.demo.custom;


import java.util.HashSet;
import java.util.Set;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.*;

public class CustomUserDetailsService implements UserDetailsService {

	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		System.out.println("当前的用户名是："+username);
		Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
		if("zhangsan".equalsIgnoreCase(username)) {
			authorities.add(new SimpleGrantedAuthority("TEST"));
			authorities.add(new SimpleGrantedAuthority("ADMIN"));
		} else {
			authorities.add(new SimpleGrantedAuthority("TEST"));
		}
		User user = new User(username, "123", authorities);
		return user;
	}
}
